
package cn.com.service.user.feign;

import cn.com.service.user.service.IUserBaseService;
import cn.qitom.core.tool.api.R;
import cn.qitom.service.user.entity.UserBase;
import cn.qitom.service.user.feign.IUserClient;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户服务Feign实现类
 *
 */

@RestController
@AllArgsConstructor

public class UserClient implements IUserClient {

	private final IUserBaseService userBaseService;

	@Override
	@GetMapping(USER_INFO)
	public R<UserBase> userInfoById(@RequestParam Long userId) {
		return	R.ok(userBaseService.getById(userId));
	}

	@Override
	@GetMapping(USER_LOGIN_INFO)
	public R<UserBase> userLoginInfo(@RequestParam String phone,@RequestParam String password) {
		UserBase one = userBaseService.getOne(new QueryWrapper<>(new UserBase()).lambda().eq(UserBase::getPhone, phone).eq(UserBase::getPassword, password));
		return	R.ok(one);
	}

	@SneakyThrows
	@Override
	@GetMapping(USER_LOGIN_INFO_BY_ACCOUNT)
	public R<UserBase> userLoginInfoByAccount(@RequestParam String account,@RequestParam String password) {
		UserBase one = userBaseService.getOne(new QueryWrapper<>(new UserBase()).lambda().eq(UserBase::getAccount, account).eq(UserBase::getPassword, password));
		return	R.ok(one);
	}
}
